using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the CountryMedium class.
	/// </summary>
	[Serializable]
	public partial class CountryMediumCollection : ActiveList<CountryMedium, CountryMediumCollection> 
	{	   
		public CountryMediumCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CountryMedia table.
	/// </summary>
	[Serializable]
	public partial class CountryMedium : ActiveRecord<CountryMedium>
	{
		#region .ctors and Default Settings
		
		public CountryMedium()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public CountryMedium(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public CountryMedium(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public CountryMedium(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CountryMedia", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarCountryID = new TableSchema.TableColumn(schema);
				colvarCountryID.ColumnName = "CountryID";
				colvarCountryID.DataType = DbType.Byte;
				colvarCountryID.MaxLength = 0;
				colvarCountryID.AutoIncrement = false;
				colvarCountryID.IsNullable = false;
				colvarCountryID.IsPrimaryKey = true;
				colvarCountryID.IsForeignKey = true;
				colvarCountryID.IsReadOnly = false;
				colvarCountryID.DefaultSetting = @"";
				
					colvarCountryID.ForeignKeyTableName = "Country";
				schema.Columns.Add(colvarCountryID);
				
				TableSchema.TableColumn colvarMediaType = new TableSchema.TableColumn(schema);
				colvarMediaType.ColumnName = "MediaTypeCode";
				colvarMediaType.DataType = DbType.Int32;
				colvarMediaType.MaxLength = 0;
				colvarMediaType.AutoIncrement = false;
				colvarMediaType.IsNullable = false;
				colvarMediaType.IsPrimaryKey = true;
				colvarMediaType.IsForeignKey = true;
				colvarMediaType.IsReadOnly = false;
				colvarMediaType.DefaultSetting = @"";
				
					colvarMediaType.ForeignKeyTableName = "MediaType";
				schema.Columns.Add(colvarMediaType);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("CountryMedia",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("CountryID")]
		public byte CountryID 
		{
			get { return GetColumnValue<byte>("CountryID"); }

			set { SetColumnValue("CountryID", value); }

		}

		  
		[XmlAttribute("MediaType")]
		public int MediaType 
		{
			get { return GetColumnValue<int>("MediaTypeCode"); }

			set { SetColumnValue("MediaTypeCode", value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Country ActiveRecord object related to this CountryMedium
		/// 
		/// </summary>
		public Adex.Country Country
		{
			get { return Adex.Country.FetchByID(this.CountryID); }

			set { SetColumnValue("CountryID", value.CountryID); }

		}

		
		
		/// <summary>
		/// Returns a MediaType ActiveRecord object related to this CountryMedium
		/// 
		/// </summary>
		public Adex.MediaType MediaType
		{
			get { return Adex.MediaType.FetchByID(this.MediaType); }

			set { SetColumnValue("MediaTypeCode", value.MediaTypeX); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(byte varCountryID,int varMediaType)
		{
			CountryMedium item = new CountryMedium();
			
			item.CountryID = varCountryID;
			
			item.MediaType = varMediaType;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(byte varCountryID,int varMediaType)
		{
			CountryMedium item = new CountryMedium();
			
				item.CountryID = varCountryID;
				
				item.MediaType = varMediaType;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string CountryID = @"CountryID";
			 public static string MediaType = @"MediaTypeCode";
						
		}

		#endregion
	}

}

